package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: ZgYn
 * @Date 2025/10/9 10:51
 * @name：ActivityController
 */
@RestController
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping
    public Result getActivities(ActivityDTO activityDTO) {
        PageResult<Activity> activities = activityService.getActivities(activityDTO);
        return Result.success(activities);
    }

    @PostMapping
    @LogAnno
    public Result save(@RequestBody Activity activity) {
        activityService.save(activity);
        return Result.success();
    }

    @LogAnno
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.delete(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getActivity(@PathVariable Integer id) {
        Activity activity = activityService.getActivity(id);
        return Result.success(activity);
    }

    @LogAnno
    @PutMapping
    public Result update(@RequestBody Activity activity) {
        activityService.update(activity);
        return Result.success();
    }

    @GetMapping("/type/{type}")
    public Result getActivitiesByType(@PathVariable Integer type) {
        List<Activity> activities = activityService.getActivitiesByType(type);
        return Result.success(activities);
    }
}
